<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/fly/Public/admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form layui-form-pane">
               <div class="layui-form-item">
                                <label for="L_title" class="layui-form-label">
                                    标题
                                </label>
                                <div class="layui-input-block">
                                    <input type="text" id="L_title" name="title" required="" lay-verify="required"
                                    autocomplete="off" value="<?php echo $res['title']; ?>"   class="layui-input">
                                    <input type="hidden" name="uid" value="<?php echo $res['uid']; ?>">
                                     <input type="hidden" name="id" value="<?php echo $res['id'] ?>">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <div class="layui-unselect fly-edit">
                                        <span type="face" title="插入表情">
                                            <i class="iconfont icon-yxj-expression" style="top: 1px;">
                                            </i>
                                        </span>
                                        <span type="picture" title="插入图片：img[src]">
                                            <i class="iconfont icon-tupian">
                                            </i>
                                        </span>
                                        <span type="href" title="超链接格式：a(href)[text]">
                                            <i class="iconfont icon-lianjie">
                                            </i>
                                        </span>
                                        <span type="code" title="插入代码或引用">
                                            <i class="iconfont icon-emwdaima" style="top: 1px;">
                                            </i>
                                        </span>
                                        <span type="hr" title="插入水平线">
                                            <hr>
                                        </span>
                                        <span type="yulan" title="预览">
                                            <i class="iconfont icon-yulan1">
                                            </i>
                                        </span>
                                    </div>
                                    <textarea id="L_content" name="content" required="" lay-verify="required"
                                    placeholder="请输入内容" class="layui-textarea fly-editor"><?php echo $res['content']; ?></textarea>
                                </div>
                                <label for="L_content" class="layui-form-label" style="top: -2px;">
                                    描述
                                </label>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                            <label class="layui-form-label">
                                                所在类别
                                            </label>
                                            <div class="layui-input-block">
                                  <select lay-verify="required" name="cid">
                                    <option></option>
                                    <?php foreach ($category as $v) { ?>
                                    <optgroup label="<?php echo $v['cname'] ?>"> 
                                         <?php foreach ($v['son'] as $value) { ?>
                                             <option value="<?php echo $value['id'] ?>" <?php if ($value['id']==$res['cid']) { echo 'selected'; } ?> ><?php echo $value['cname'] ?></option>
                                         <?php } ?>   
                                    </optgroup>
                                    <?php  } ?>
                                  </select>

                                            </div>
                                </div>
                            </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-filter="add" lay-submit>
                        保存
                    </button>
                </div>
            </form>
        </div>
        <script src="/fly/Public/admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="/fly/Public/admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer','layedit'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer
              ,layedit = layui.layedit;


                layedit.set({
                  uploadImage: {
                    url: "./upimg.json" //接口url
                    ,type: 'post' //默认post
                  }
                })
  
            //创建一个编辑器
            index = layedit.build('L_content');
            
              

              //监听提交
              form.on('submit(add)', function(data){

                console.log(data);
                content = layedit.getContent(index);
               if (content.length<10) {
                   layer.msg('问题内容少于10，请重新输入',function(){});
                   return false;
               };             
               data.field.content = content;

                 $.ajax({
                   url: '<?php echo U('Admin/Question/checkedit');?>',
                   type: 'post',
                   dataType: 'json',
                   data: data.field,
               })
               .done(function(respones) {
                console.log("success");
                if (respones.error=1) {
                    // alert(111);
                    layer.msg(respones.info,{icon: 6},function(){
                      // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    });
                }else{
                     // alert(222);
                    layer.msg(respones.info,{icon: 6}); 
                };
                   
               })
               .fail(function() {
                 alert(333);
                   console.log("error");
               })
                // layer.alert("保存成功", {icon: 6},function () {
                //     // 获得frame索引
                //     var index = parent.layer.getFrameIndex(window.name);
                //     //关闭当前frame
                //     parent.layer.close(index);
                // });
                return false;
              }); 
            });
        </script>
        <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
    </body>

</html>